<%@page import="java.util.*,com.cs.beneficios.common.ConnectionFactory,com.cs.beneficios.business.model.SubProgramaVO,com.cs.beneficios.common.entity.Consultas,java.sql.ResultSet,com.cs.beneficios.common.entity.database,java.util.Vector,com.cs.paoyer.administration.business.model.UserVO,java.text.SimpleDateFormat,java.util.Calendar"%>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"%>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
<%@ taglib uri="/WEB-INF/displaytag.tld" prefix="display"%>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<link href="<%= request.getContextPath() + "/css/bloques.css" %>" rel="stylesheet" type="text/css">
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Activar Correcta</title>
  </head>
  <body>
    <P></P>
    <P></P>

<%
  Vector codsub = new Vector ();
  boolean b = false;
  int modificar;
  ResultSet rs = null;
  //ConnectionFactory cf = new ConnectionFactory("beneficios","beneficios");
  ConnectionFactory cf = new ConnectionFactory();
  Consultas consulta = new Consultas(cf); 
  String strcont = request.getParameter("cont");
  int cont =Integer.parseInt(strcont.trim());
  int i=0;
  List noactivar = new LinkedList();
  List activos = new LinkedList();
  for(i=0; i<cont; i++){
   String activar = request.getParameter("Activar"+i);
      if(activar != null){       
       b = consulta.valProgActivo(activar);
       if(b){
       rs = consulta.getInfoact(activar);
         if(rs != null){
          try{
              rs.next();
              SubProgramaVO objsubprogVO = new SubProgramaVO();
              objsubprogVO.setCodePrograma(new Long(rs.getString("codprog")));
              objsubprogVO.setNombre(rs.getString("subprograma"));
              objsubprogVO.setNombrePrograma(rs.getString("programa"));
              
              noactivar.add(objsubprogVO);
            }catch(Exception e){
                e.printStackTrace();}
                }
       }else{
          rs = consulta.getInfoact2(activar);
            if(rs != null){
            try{
              rs.next();
            SubProgramaVO objsubprogVO = new SubProgramaVO();
            //Proceso para la auditoria
            UserVO user = (UserVO) request.getSession().getAttribute("userInfo");
            String terminalAddress = request.getRemoteAddr();
            String strTerminal = ("WEB="+terminalAddress);
            Calendar c = Calendar.getInstance(); 
            SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");   
            //Fin del proceso
            String strArr[] = {user.getName(), dateFormat.format(c.getTime()),strTerminal,activar};
            modificar = consulta.getActivarSub2(strArr);   
            objsubprogVO.setNombre(rs.getString("subprograma"));
            objsubprogVO.setNombrePrograma(rs.getString("programa"));
            
            activos.add(objsubprogVO);
            }catch(Exception e){
              e.printStackTrace();}
            }
           
         }
       }
  }
  
  if(noactivar.size()>1)
  {
    request.setAttribute("Lista1",noactivar);
  }
  if(noactivar.size()== 1)
  {
    request.setAttribute("Lista2",noactivar);
  }  
  cf.closeConnection(consulta.getConn());
%>
<logic:present scope="request" name="Lista1">
<div align="center">
  <table cellspacing="2" cellpadding="1" border="0" width="80%" align="center">
    <tr>
      <td class="celdatabla" align="center">No es posible activar los beneficios, el programa no esta activo</td>
    </tr>
  </table>
  <P></P>
 <table  cellspacing="3" cellpadding="2" border="0" width="90%" align="center">
  <tr>
  <td>
  <display:table name="requestScope.Lista1" class="bordesTable"  id="list" cellpadding="3" cellspacing="1"  style="width:100%">
     <display:column headerClass="headerTable" title="Subprograma" class="Numero" sortable="false">
        <bean:write name="list" property="nombre"/> 
     </display:column>   
     <display:column headerClass="headerTable" title="Programa" class="Numero" sortable="false">
        <bean:write name="list" property="nombrePrograma"/> 
     </display:column>
     <display:column headerClass="headerTable" title="Activar Programa" class="Numero" sortable="false">
         <html:link paramId="Codigo" paramName="list" paramProperty="codePrograma" page="/subprogramas/ActivarSubprogramas.do?ori=activar1">
                   <div align="center"><img src="<%= request.getContextPath() + "/images/activar.gif" %>" width="16" height="16" border="0"></div>
              </html:link> 
     </display:column>
  </display:table> 
  </td>
  </tr>
  </table>
  <P></P>
  <table cellspacing="2" cellpadding="1" border="0" width="80%" align="center">
    <tr>
      <td>
        <P>
          <a href="javascript:window.history.back()">
            <img src="<%=request.getContextPath() + "/images/BACK1-1.gif"%>" border="0"/>
          </a>
        </P>
      </td>
    </tr>
  </table>
  <P></P>
</div>
</logic:present>
<P></P>
<logic:present scope="request" name="Lista2">
<div align="center">
  <table cellspacing="1" cellpadding="2" border="0" width="80%" align="center">
    <tr>
      <td class="celdatabla" align="center">No es posible activar el beneficio, el programa no esta activo</td>
    </tr>
  </table>
  <P></P>
 <table  cellspacing="3" cellpadding="2" border="0" width="90%" align="center">
  <tr>
  <td>
  <display:table name="requestScope.Lista2" class="bordesTable" id="list" cellpadding="3" cellspacing="1"  style="width:100%">
     <display:column headerClass="headerTable" title="Subprograma" class="Numero" sortable="false">
        <bean:write name="list" property="nombre"/> 
     </display:column>   
     <display:column headerClass="headerTable" title="Programa" class="Numero" sortable="false">
        <bean:write name="list" property="nombrePrograma"/> 
     </display:column>
     <display:column headerClass="headerTable" title="Activar Programa" class="Numero" sortable="false">
      <html:link paramId="Codigo" paramName="list" paramProperty="codePrograma" page="/subprogramas/ActivarSubprogramas.do?ori=activar1">
        <div align="center"><img src="<%= request.getContextPath() + "/images/activar.gif" %>" width="16" height="16" border="0"></div>
       </html:link> 
     </display:column>
  </display:table> 
  </td>
  </tr>
  </table>
  <P></P>
  <table cellspacing="1" cellpadding="2" border="0" width="80%" align="center">
    <tr>
      <td>
        <a href="javascript:window.history.back()">
          <img src="<%=request.getContextPath() + "/images/BACK1-1.gif"%>" border="0"/>
        </a></td>
    </tr>
  </table>
</div>
</logic:present>
<%
  
  if (activos.size() >0){
    if(activos.size() > 1){
      request.setAttribute("Lista3",activos);
    }
    if(activos.size()== 1){
      request.setAttribute("Lista4",activos);
    }
  
%>
  <logic:present scope="request" name="Lista3">
<div align="center">
  <table cellspacing="2" cellpadding="1" border="0" width="80%" align="center">
    <tr>
      <td class="celdatabla" align="center">Los Beneficios fueron activados</td>
    </tr>
  </table>
  <P></P>
 <table  cellspacing="3" cellpadding="2" border="0" width="90%" align="center">
  <tr>
  <td>
  <display:table name="requestScope.Lista3" class="bordesTable"  id="list" cellpadding="3" cellspacing="1"  style="width:100%">
     <display:column headerClass="headerTable" title="Beneficio" class="Numero" sortable="false">
        <bean:write name="list" property="nombre"/> 
     </display:column>   
     <display:column headerClass="headerTable" title="Programa" class="Numero" sortable="false">
        <bean:write name="list" property="nombrePrograma"/> 
     </display:column>
  </display:table> 
  </td>
  </tr>
  </table>
  <P></P>
  <table cellspacing="1" cellpadding="2" border="0" width="80%" align="center">
    <tr>
      <td><a href="<%=request.getContextPath()+"/programas/ConsultarPrograma.do"%>">Volver a Programas</a></td>
        <td>
        <a href="<%=request.getContextPath()+"/subprogramas/ConsultarSubprograma.do"%>">Volver a Beneficios</a></td>
    </tr>
  </table>
  <P></P>
</div>
</logic:present>
<P></P>
<logic:present scope="request" name="Lista4">
<div align="center">
  <table cellspacing="1" cellpadding="2" border="0" width="80%" align="center">
    <tr>
      <td class="celdatabla" align="center">El Beneficio fue activado</td>
    </tr>
  </table>
  <P></P>
 <table  cellspacing="3" cellpadding="2" border="0" width="90%" align="center">
  <tr>
  <td>
  <display:table name="requestScope.Lista4" class="bordesTable" id="list" cellpadding="3" cellspacing="1"  style="width:100%">
     <display:column headerClass="headerTable" title="Beneficio" class="Numero" sortable="false">
        <bean:write name="list" property="nombre"/> 
     </display:column>   
     <display:column headerClass="headerTable" title="Programa" class="Numero" sortable="false">
        <bean:write name="list" property="nombrePrograma"/> 
     </display:column>
  </display:table> 
  </td>
  </tr>
  </table>
  <P></P>
  <table cellspacing="1" cellpadding="2" border="0" width="80%" align="center">
    <tr>
      <td><a href="<%=request.getContextPath()+"/programas/ConsultarPrograma.do"%>">Volver a Programas</a></td>
        <td>
        <a href="<%=request.getContextPath()+"/subprogramas/ConsultarSubprograma.do"%>">Volver a Beneficios</a></td>
    </tr>
  </table>
</div>
</logic:present>
  <%}%>
  </body>
</html>
